// index.js
// 获取应用实例
let backgroundAudioManager = null
Page({
  data: {
  },
  onLoad() {
    backgroundAudioManager = mp.getBackgroundAudioManager()
    backgroundAudioManager.title = '此时此刻title'
    backgroundAudioManager.epname = '此时此刻'
    backgroundAudioManager.singer = '许巍'
    backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
    backgroundAudioManager.playbackRate = 1.5
    backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46'
    backgroundAudioManager.referrerPolicy = "origin"
    backgroundAudioManager.onPlay((e) => {
      console.log('执行：onPlay',e)
      console.log("src:",backgroundAudioManager.src)
    })

    this.handler()
    setInterval(() => {
      this.setData({
        duration: backgroundAudioManager.duration,
        currentTime: backgroundAudioManager.currentTime,
        paused: backgroundAudioManager.paused,
        buffered: backgroundAudioManager.buffered,
      })
    }, 2000);
  },

  seek() {
    backgroundAudioManager.seek(61)
  },

  changeSrc() {
    backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46'
    backgroundAudioManager.title = 'title'
    backgroundAudioManager.epname = 'epname'
    backgroundAudioManager.singer = '小程序'
    backgroundAudioManager.startTime =20
    backgroundAudioManager.startTime =20
    backgroundAudioManager.protocol='http'
    backgroundAudioManager.referrerPolicy = "origin"
  },
// IDE不支持
  changeHLSSrc() {
    backgroundAudioManager.title = 'title'
    backgroundAudioManager.protocol='hls'
    backgroundAudioManager.playbackRate = 1
    backgroundAudioManager.startTime =0
    backgroundAudioManager.src = 'https://play.radiofoshan.com.cn/live/1400389414_BSID_46_audio.m3u8'
  },
  handler(manager) {
    backgroundAudioManager.onCanplay((e) => {
      console.log('执行：onCanplay',e)
    })
    backgroundAudioManager.onWaiting((e) => {
      console.log('执行：onWaiting',e)
    })
    backgroundAudioManager.onError((err) => {
      console.log('执行：onError', err)
    })
    backgroundAudioManager.onPlay((e) => {
      console.log('执行：onPlay',e)
      console.log("src:",backgroundAudioManager.src)
    })
    backgroundAudioManager.onPause((e) => {
      console.log('执行：onPause',e)
    })
    backgroundAudioManager.onSeeking((e) => {
      console.log('执行：onSeeking',e)
    })
    backgroundAudioManager.onSeeked((e) => {
      console.log('执行：onSeeked',e)
    })
    backgroundAudioManager.onEnded(() => {
      backgroundAudioManager.paused = 'asdasd'
      console.log('执行：onEnded')
    })
    backgroundAudioManager.onStop((e) => {
      console.log('执行：onStop',e)
    })
    backgroundAudioManager.onTimeUpdate((e) => {
      console.log('执行：onTimeUpdate',e)
    })
    backgroundAudioManager.onNext(() => {
      console.log('执行：onNext')
    })
    backgroundAudioManager.onPrev(() => {
      console.log('执行：onPrev')
    })
  },

  play() {
    backgroundAudioManager.play()
    console.log("src:",backgroundAudioManager.src)
    console.log("duration:",backgroundAudioManager.duration)
    console.log("backgroundAudioManager:",backgroundAudioManager)
  },

  stop() {
    backgroundAudioManager.stop()
  },

  pause() {
    backgroundAudioManager.pause()
    console.log("backgroundAudioManager:",backgroundAudioManager)
  },

  onUnload() {
    // backgroundAudioManager.stop()
  },
  onHide() {
    // backgroundAudioManager.stop()
  }

})
